﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Threading;
using System.Web;
using System.Security.Cryptography;
using System.Text;

namespace EAppointment.Models
{
    public class EmailSender : EmailVerfier
    {
        public EmailSender(string email, BaseUserInfo user)
            : base(email, user) { }

        public void SendCode()
        {
            MailMessage message = new MailMessage(new MailAddress("contact@xiyoumobile.com"), new MailAddress(Email));
            message.Subject = "请验证您的E预约账号！";

            message.Body = string.Format("尊敬的用户：\n\t您好！感谢您使用E预约！\n请访问下面链接验证您的账号：<a href=\"http://{0}/User/Verify?p={1}&id={2}\">http://{0}/User/Verify?p={1}&id={2}</a>\n若您没有注册该账号，请忽略此邮件！\n",
                "xiyoumobile.com",
                GenerateCode(),
                UserInfo.ID);

            message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            SmtpClient client = new SmtpClient("smtp.exmail.qq.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials = new System.Net.NetworkCredential("contact@xiyoumobile.com", "xiyou3g");

            try
            {
                client.Send(message);
            }
            catch
            {
                Console.Write("shit");
            }
        }
    }
}